package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.contrarywind.adapter.WheelAdapter;
import com.contrarywind.listener.OnItemSelectedListener;
import com.contrarywind.view.WheelView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.HourAdapter;
import flc.ast.adapter.WageAdapter;
import flc.ast.bean.HourBean;
import flc.ast.bean.OvertimeBean;
import flc.ast.bean.WageBean;
import flc.ast.databinding.ActivityAddOvertimeBinding;
import flc.ast.utils.Content;
import flc.ast.utils.MyDatabase;
import stark.common.basic.utils.SPUtil;
import stark.common.basic.utils.Str2NumUtil;

public class AddOvertimeActivity extends BaseAc<ActivityAddOvertimeBinding> {

    public static OvertimeBean overtimeBean;
    private int type;
    private int overtimeType, leaveType;
    private Dialog mySelDateDialog, mySelWageDialog, mySelLeaveDialog;
    private WheelView wheelView1, wheelView2, wheelView3;
    private SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
    private HourAdapter overtimeHourAdapter, leaveHourAdapter;
    private double overtimeWage, leaveWage;
    private int overtimeHour, overtimeMinute, leaveHour, leaveMinute, overtimeHourPos, leaveHourPos, overtimeWagePos, leaveWagePos;
    private WageAdapter overtimeWageAdapter, leaveWageAdapter;

    @Override

    protected int onCreate() {
        return R.layout.activity_add_overtime;
    }

    @Override
    protected void initView() {
        mDataBinding.ivAddOvertimeBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivDelete.setOnClickListener(this);
        mDataBinding.ivConfirm.setOnClickListener(this);
        mDataBinding.llRecordOvertime.setOnClickListener(this);
        mDataBinding.llRecordLeave.setOnClickListener(this);
        mDataBinding.tvOvertimeDate.setOnClickListener(this);
        mDataBinding.tvLeaveDate.setOnClickListener(this);
        mDataBinding.ivOvertimeUnitSel.setOnClickListener(this);
        mDataBinding.ivLeaveUnitSel.setOnClickListener(this);
        mDataBinding.tvOvertimeWage.setOnClickListener(this);
        mDataBinding.tvLeaveWage.setOnClickListener(this);

        mDataBinding.rvOvertimeHourList.setLayoutManager(new GridLayoutManager(mContext, 6));
        overtimeHourAdapter = new HourAdapter();
        mDataBinding.rvOvertimeHourList.setAdapter(overtimeHourAdapter);
        overtimeHourAdapter.setOnItemClickListener(this);

        mDataBinding.rvLeaveHourList.setLayoutManager(new GridLayoutManager(mContext, 6));
        leaveHourAdapter = new HourAdapter();
        mDataBinding.rvLeaveHourList.setAdapter(leaveHourAdapter);
        leaveHourAdapter.setOnItemClickListener(this);

        overtimeWageAdapter = new WageAdapter();
        overtimeWageAdapter.setOnItemClickListener(this);

        leaveWageAdapter = new WageAdapter();
        leaveWageAdapter.setOnItemClickListener(this);

        //选择日期弹框
        selDateDialog();
        //设置时间选择布局
        setTimeView();
        //选择工资弹框
        selWageDialog();
        //选择请假类型弹框
        selLeaveDialog();
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivDelete://删除
                if (overtimeBean == null) {
                    return;
                }
                MyDatabase.getInstance(mContext).getOvertimeDao().deleteOvertime(overtimeBean);
                ToastUtils.showShort(getString(R.string.delete_suc));
                finish();
                break;
            case R.id.ivConfirm://确定
                save();
                break;
            case R.id.llRecordOvertime://记加班
                clearSelection();
                type = 0;
                mDataBinding.tvRecordOvertime.setTextColor(Color.parseColor("#5476FC"));
                mDataBinding.tvRecordOvertime.setTextSize(18);
                mDataBinding.ivRecordOvertimeSel.setVisibility(View.VISIBLE);
                mDataBinding.llOvertime.setVisibility(View.VISIBLE);
                break;
            case R.id.llRecordLeave://记请假
                clearSelection();
                type = 1;
                mDataBinding.tvRecordLeave.setTextColor(Color.parseColor("#5476FC"));
                mDataBinding.tvRecordLeave.setTextSize(18);
                mDataBinding.ivRecordLeaveSel.setVisibility(View.VISIBLE);
                mDataBinding.llLeave.setVisibility(View.VISIBLE);
                break;
            case R.id.tvOvertimeDate://记加班日期
            case R.id.tvLeaveDate://记请假日期
                mySelDateDialog.show();
                break;
            case R.id.ivOvertimeUnitSel://加班时长
                if (overtimeType == 0) {
                    overtimeType = 1;
                    mDataBinding.llOvertimeMinute.setVisibility(View.GONE);
                    mDataBinding.llOvertimeHour.setVisibility(View.VISIBLE);
                } else if (overtimeType == 1) {
                    overtimeType = 0;
                    mDataBinding.llOvertimeMinute.setVisibility(View.VISIBLE);
                    mDataBinding.llOvertimeHour.setVisibility(View.GONE);
                }
                break;
            case R.id.ivLeaveUnitSel://请假时长
                if (leaveType == 0) {
                    leaveType = 1;
                    mDataBinding.llLeaveMinute.setVisibility(View.GONE);
                    mDataBinding.llLeaveHour.setVisibility(View.VISIBLE);
                } else if (leaveType == 1) {
                    leaveType = 0;
                    mDataBinding.llLeaveMinute.setVisibility(View.VISIBLE);
                    mDataBinding.llLeaveHour.setVisibility(View.GONE);
                }
                break;
            case R.id.tvOvertimeWage://工钱
                mySelWageDialog.show();
                break;
            case R.id.tvLeaveWage://请假类型
                mySelLeaveDialog.show();
                break;
            //选择工资弹框
            case R.id.tvDialogSelWageSet://工资设定
                mySelWageDialog.dismiss();
                Intent intent = new Intent(this, WageSetActivity.class);
                startActivityForResult(intent, Content.SEL_WAGE);
                break;
            case R.id.ivDialogSelWageCancel://取消
                mySelWageDialog.dismiss();
                break;
            case R.id.ivDialogSelWageRight://确定
                mySelWageDialog.dismiss();
                overtimeWage = overtimeWageAdapter.getItem(overtimeWagePos).getWage();
                mDataBinding.tvOvertimeWage.setText(overtimeWageAdapter.getItem(overtimeWagePos).getName());
                break;
            //选择请假类型弹框
            case R.id.ivDialogSelLeaveCancel://取消
                mySelLeaveDialog.dismiss();
                break;
            case R.id.ivDialogSelLeaveRight://确定
                mySelLeaveDialog.dismiss();
                leaveWage = leaveWageAdapter.getItem(leaveWagePos).getWage();
                mDataBinding.tvLeaveWage.setText(leaveWageAdapter.getItem(leaveWagePos).getName());
                break;
            //选择日期弹框
            case R.id.ivDialogSelDateCancel://取消
                mySelDateDialog.dismiss();
                break;
            case R.id.ivDialogSelDateRight://确定
                mySelDateDialog.dismiss();
                int year = wheelView1.getCurrentItem() + 1980;
                int moon = wheelView2.getCurrentItem() + 1;
                int day = wheelView3.getCurrentItem() + 1;
                String selDate = year + "年" + (moon < 10 ? "0" + moon : moon) + "月" + (day < 10 ? "0" + day : day) + "日";
                long times = TimeUtils.string2Millis(selDate, new SimpleDateFormat("yyyy年MM月dd日"));
                selDate = TimeUtils.millis2String(times, new SimpleDateFormat("yyyy年MM月dd日 （EEEE）"));
                if (type == 0) {
                    mDataBinding.tvOvertimeDate.setText(selDate);
                } else if (type == 1) {
                    mDataBinding.tvLeaveDate.setText(selDate);
                }
                break;

        }
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        if (adapter == overtimeHourAdapter) {
            overtimeHourAdapter.getItem(overtimeHourPos).setSelected(false);
            overtimeHourAdapter.notifyItemChanged(overtimeHourPos);
            overtimeHourPos = position;
            overtimeHourAdapter.getItem(position).setSelected(true);
            overtimeHourAdapter.notifyItemChanged(position);
            overtimeHour = overtimeHourAdapter.getItem(position).getHour();
            overtimeMinute = overtimeHourAdapter.getItem(position).getMinute();
            mDataBinding.tvOvertimeDuration.setText(overtimeHour + getString(R.string.unit_hour) + overtimeMinute + getString(R.string.unit_minute));
        } else if (adapter == leaveHourAdapter) {
            leaveHourAdapter.getItem(leaveHourPos).setSelected(false);
            leaveHourAdapter.notifyItemChanged(leaveHourPos);
            leaveHourPos = position;
            leaveHourAdapter.getItem(position).setSelected(true);
            leaveHourAdapter.notifyItemChanged(position);
            leaveHour = leaveHourAdapter.getItem(position).getHour();
            leaveMinute = leaveHourAdapter.getItem(position).getMinute();
            mDataBinding.tvLeaveDuration.setText(leaveHour + getString(R.string.unit_hour) + leaveMinute + getString(R.string.unit_minute));
        } else if (adapter == overtimeWageAdapter) {
            overtimeWageAdapter.getItem(overtimeWagePos).setSelected(false);
            overtimeWageAdapter.notifyItemChanged(overtimeWagePos);
            overtimeWagePos = position;
            overtimeWageAdapter.getItem(position).setSelected(true);
            overtimeWageAdapter.notifyItemChanged(position);
        } else if (adapter == leaveWageAdapter) {
            leaveWageAdapter.getItem(leaveWagePos).setSelected(false);
            leaveWageAdapter.notifyItemChanged(leaveWagePos);
            leaveWagePos = position;
            leaveWageAdapter.getItem(position).setSelected(true);
            leaveWageAdapter.notifyItemChanged(position);
        }
    }

    @Override
    protected void initData() {
        if (overtimeBean == null) {
            String date = TimeUtils.getNowString(new SimpleDateFormat("yyyy年MM月dd日 （EEEE）"));
            mDataBinding.tvOvertimeDate.setText(date);
            mDataBinding.tvLeaveDate.setText(date);
            mDataBinding.tvOvertimeDuration.setText(overtimeHour + getString(R.string.unit_hour) + overtimeMinute + getString(R.string.unit_minute));
            mDataBinding.tvLeaveDuration.setText(leaveHour + getString(R.string.unit_hour) + leaveMinute + getString(R.string.unit_minute));
        } else {
            String date = TimeUtils.millis2String(overtimeBean.getDate(), new SimpleDateFormat("yyyy年MM月dd日 （EEEE）"));
            mDataBinding.tvOvertimeDate.setText(date);
            mDataBinding.tvLeaveDate.setText(date);
            mDataBinding.tvOvertimeDuration.setText(overtimeHour + getString(R.string.unit_hour) + overtimeMinute + getString(R.string.unit_minute));
            mDataBinding.tvLeaveDuration.setText(leaveHour + getString(R.string.unit_hour) + leaveMinute + getString(R.string.unit_minute));
            if (overtimeBean.isLeave()) {
                clearSelection();
                type = 1;
                mDataBinding.tvRecordLeave.setTextColor(Color.parseColor("#5476FC"));
                mDataBinding.tvRecordLeave.setTextSize(18);
                mDataBinding.ivRecordLeaveSel.setVisibility(View.VISIBLE);
                mDataBinding.llLeave.setVisibility(View.VISIBLE);
                leaveHour = (int) overtimeBean.getDuration();
                leaveMinute = ((int) (overtimeBean.getDuration() * 10) % 10);
                mDataBinding.tvLeaveDuration.setText(leaveHour + getString(R.string.unit_hour) + leaveMinute + getString(R.string.unit_minute));
                overtimeWage = overtimeWageAdapter.getItem(overtimeWagePos).getWage();
                leaveWage = overtimeBean.getHour();
                mDataBinding.tvLeaveWage.setText(overtimeBean.getName() + getString(R.string.hour_income, leaveWage));
                mDataBinding.tvOvertimeWage.setText(overtimeWageAdapter.getItem(overtimeWagePos).getName());
            } else {
                overtimeHour = (int) overtimeBean.getDuration();
                overtimeMinute = ((int) (overtimeBean.getDuration() * 10) % 10);
                mDataBinding.tvOvertimeDuration.setText(overtimeHour + getString(R.string.unit_hour) + overtimeMinute + getString(R.string.unit_minute));
                overtimeWage = overtimeBean.getHour();
                leaveWage = leaveWageAdapter.getItem(leaveWagePos).getWage();
                mDataBinding.tvOvertimeWage.setText(overtimeBean.getName() + getString(R.string.hour_income, overtimeWage));
                mDataBinding.tvLeaveWage.setText(leaveWageAdapter.getItem(leaveWagePos).getName());
            }
        }

        List<HourBean> listHour = new ArrayList<>();
        listHour.add(new HourBean(0.5, 0, 30, true));
        listHour.add(new HourBean(1, 1, 0, false));
        listHour.add(new HourBean(1.5, 1, 30, false));
        listHour.add(new HourBean(2, 2, 0, false));
        listHour.add(new HourBean(2.5, 2, 30, false));
        listHour.add(new HourBean(3, 3, 0, false));
        listHour.add(new HourBean(3.5, 3, 30, false));
        listHour.add(new HourBean(4, 4, 0, false));
        listHour.add(new HourBean(4.5, 4, 30, false));
        listHour.add(new HourBean(5, 5, 0, false));
        listHour.add(new HourBean(5.5, 5, 30, false));
        listHour.add(new HourBean(6, 6, 0, false));
        listHour.add(new HourBean(6.5, 6, 30, false));
        listHour.add(new HourBean(7, 7, 0, false));
        listHour.add(new HourBean(7.5, 7, 30, false));
        listHour.add(new HourBean(8, 8, 0, false));
        listHour.add(new HourBean(8.5, 8, 30, false));
        listHour.add(new HourBean(9, 9, 0, false));
        listHour.add(new HourBean(9.5, 9, 30, false));
        listHour.add(new HourBean(10, 10, 0, false));
        listHour.add(new HourBean(10.5, 10, 30, false));
        listHour.add(new HourBean(11, 11, 0, false));
        listHour.add(new HourBean(11.5, 11, 30, false));
        listHour.add(new HourBean(12, 12, 0, false));
        overtimeHourAdapter.setList(listHour);
        leaveHourAdapter.setList(listHour);
    }

    private void save() {
        if (overtimeBean == null) {
            String name = "";
            long date = 0;
            double duration = 0, hour = 0, income = 0;
            boolean isLeave = false;
            if (type == 0) {
                String str = mDataBinding.tvOvertimeWage.getText().toString();
                int index = str.lastIndexOf('（');
                name = str.substring(0, index);
                date = TimeUtils.string2Millis(mDataBinding.tvOvertimeDate.getText().toString(), new SimpleDateFormat("yyyy年MM月dd日 （EEEE）"));
                duration = overtimeHour + overtimeMinute / 60.0;
                hour = overtimeWage;
            } else if (type == 1) {
                String str = mDataBinding.tvLeaveWage.getText().toString();
                int index = str.lastIndexOf('（');
                name = str.substring(0, index);
                date = TimeUtils.string2Millis(mDataBinding.tvLeaveDate.getText().toString(), new SimpleDateFormat("yyyy年MM月dd日 （EEEE）"));
                duration = leaveHour + leaveMinute / 60.0;
                hour = leaveWage;
                isLeave = true;
            }
            income = duration * hour;
            OvertimeBean bean = new OvertimeBean(date, name, hour, duration, income, isLeave);
            MyDatabase.getInstance(mContext).getOvertimeDao().insertOvertime(bean);
        } else {
            String name = "";
            long date = 0;
            double duration = 0, hour = 0, income = 0;
            boolean isLeave = false;
            if (type == 0) {
                String str = mDataBinding.tvOvertimeWage.getText().toString();
                int index = str.lastIndexOf('（');
                name = str.substring(0, index);
                date = TimeUtils.string2Millis(mDataBinding.tvOvertimeDate.getText().toString(), new SimpleDateFormat("yyyy年MM月dd日 （EEEE）"));
                duration = overtimeHour + overtimeMinute / 60;
                hour = overtimeWage;
            } else if (type == 1) {
                String str = mDataBinding.tvLeaveWage.getText().toString();
                int index = str.lastIndexOf('（');
                name = str.substring(0, index);
                date = TimeUtils.string2Millis(mDataBinding.tvLeaveDate.getText().toString(), new SimpleDateFormat("yyyy年MM月dd日 （EEEE）"));
                duration = leaveHour + leaveMinute / 60;
                hour = leaveWage;
                isLeave = true;
            }
            income = duration * hour;
            overtimeBean.setDate(date);
            overtimeBean.setName(name);
            overtimeBean.setHour(hour);
            overtimeBean.setDuration(duration);
            overtimeBean.setIncome(income);
            overtimeBean.setLeave(isLeave);
            MyDatabase.getInstance(mContext).getOvertimeDao().updateOvertime(overtimeBean);
        }
        ToastUtils.showShort(getString(R.string.save_success));
        finish();
    }

    //设置时间选择布局
    private void setTimeView() {
        mDataBinding.wheelView1.setDividerColor(Color.parseColor("#2E979797"));
        mDataBinding.wheelView1.setTextColorCenter(Color.parseColor("#000000"));
        mDataBinding.wheelView1.setLineSpacingMultiplier(2.5f);
        mDataBinding.wheelView1.setDividerType(WheelView.DividerType.WRAP);
        mDataBinding.wheelView1.setCurrentItem(0);
        mDataBinding.wheelView1.setItemsVisibleCount(3);
        mDataBinding.wheelView1.setCyclic(true);
        mDataBinding.wheelView1.setTextSize(20);
        mDataBinding.wheelView2.setDividerColor(Color.parseColor("#2E979797"));
        mDataBinding.wheelView2.setTextColorCenter(Color.parseColor("#000000"));
        mDataBinding.wheelView2.setLineSpacingMultiplier(2.5f);
        mDataBinding.wheelView2.setDividerType(WheelView.DividerType.WRAP);
        mDataBinding.wheelView2.setCurrentItem(0);
        mDataBinding.wheelView2.setItemsVisibleCount(3);
        mDataBinding.wheelView2.setCyclic(true);
        mDataBinding.wheelView2.setTextSize(20);
        mDataBinding.wheelView3.setDividerColor(Color.parseColor("#2E979797"));
        mDataBinding.wheelView3.setTextColorCenter(Color.parseColor("#000000"));
        mDataBinding.wheelView3.setLineSpacingMultiplier(2.5f);
        mDataBinding.wheelView3.setDividerType(WheelView.DividerType.WRAP);
        mDataBinding.wheelView3.setCurrentItem(0);
        mDataBinding.wheelView3.setItemsVisibleCount(3);
        mDataBinding.wheelView3.setCyclic(true);
        mDataBinding.wheelView3.setTextSize(20);
        mDataBinding.wheelView4.setDividerColor(Color.parseColor("#2E979797"));
        mDataBinding.wheelView4.setTextColorCenter(Color.parseColor("#000000"));
        mDataBinding.wheelView4.setLineSpacingMultiplier(2.5f);
        mDataBinding.wheelView4.setDividerType(WheelView.DividerType.WRAP);
        mDataBinding.wheelView4.setCurrentItem(0);
        mDataBinding.wheelView4.setItemsVisibleCount(3);
        mDataBinding.wheelView4.setCyclic(true);
        mDataBinding.wheelView4.setTextSize(20);

        //设置滚轮数据
        List<String> listHour = new ArrayList<>();//时
        for (int i = 0; i < 24; i++) {
            listHour.add(String.valueOf(i));
        }
        List<String> listMinute = new ArrayList<>();//分
        for (int i = 0; i < 60; i++) {
            listMinute.add(String.valueOf(i));
        }

        WheelAdapter adapter1 = new ArrayWheelAdapter(listHour);
        mDataBinding.wheelView1.setAdapter(adapter1);
        mDataBinding.wheelView3.setAdapter(adapter1);
        WheelAdapter adapter2 = new ArrayWheelAdapter(listMinute);
        mDataBinding.wheelView2.setAdapter(adapter2);
        mDataBinding.wheelView4.setAdapter(adapter2);

        mDataBinding.wheelView1.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                overtimeHour = index;
                overtimeMinute = mDataBinding.wheelView2.getCurrentItem();
                mDataBinding.tvOvertimeDuration.setText(overtimeHour + getString(R.string.unit_hour) + overtimeMinute + getString(R.string.unit_minute));
            }
        });
        mDataBinding.wheelView2.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                overtimeHour = mDataBinding.wheelView1.getCurrentItem();
                overtimeMinute = index;
                mDataBinding.tvOvertimeDuration.setText(overtimeHour + getString(R.string.unit_hour) + overtimeMinute + getString(R.string.unit_minute));
            }
        });
        mDataBinding.wheelView3.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                leaveHour = index;
                leaveMinute = mDataBinding.wheelView4.getCurrentItem();
                mDataBinding.tvLeaveDuration.setText(leaveHour + getString(R.string.unit_hour) + leaveMinute + getString(R.string.unit_minute));
            }
        });
        mDataBinding.wheelView4.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                leaveHour = mDataBinding.wheelView3.getCurrentItem();
                leaveMinute = index;
                mDataBinding.tvLeaveDuration.setText(leaveHour + getString(R.string.unit_hour) + leaveMinute + getString(R.string.unit_minute));
            }
        });
    }

    //选择日期弹框
    private void selDateDialog() {
        mySelDateDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_sel_date, null);
        mySelDateDialog.setContentView(inflate);
        //获取当前Activity所在的窗体
        Window dialogWindow = mySelDateDialog.getWindow();
        //设置Dialog从窗体中心弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics dm = getResources().getDisplayMetrics();
        lp.width = (int) (dm.widthPixels * 1);
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        ImageView dialogCancel = inflate.findViewById(R.id.ivDialogSelDateCancel);
        ImageView dialogRight = inflate.findViewById(R.id.ivDialogSelDateRight);
        wheelView1 = inflate.findViewById(R.id.wheel_view1);
        wheelView2 = inflate.findViewById(R.id.wheel_view2);
        wheelView3 = inflate.findViewById(R.id.wheel_view3);
        dialogCancel.setOnClickListener(this);
        dialogRight.setOnClickListener(this);
        wheelView1.setDividerColor(Color.parseColor("#2E979797"));
        wheelView1.setTextColorCenter(Color.parseColor("#000000"));
        wheelView1.setLineSpacingMultiplier(2.5f);
        wheelView1.setDividerType(WheelView.DividerType.WRAP);
        wheelView1.setCurrentItem(43);
        wheelView1.setItemsVisibleCount(5);
        wheelView1.setCyclic(true);
        wheelView1.setTextSize(18);
        wheelView2.setDividerColor(Color.parseColor("#2E979797"));
        wheelView2.setTextColorCenter(Color.parseColor("#000000"));
        wheelView2.setLineSpacingMultiplier(2.5f);
        wheelView2.setDividerType(WheelView.DividerType.WRAP);
        wheelView2.setCurrentItem(0);
        wheelView2.setItemsVisibleCount(5);
        wheelView2.setCyclic(true);
        wheelView2.setTextSize(15);
        wheelView3.setDividerColor(Color.parseColor("#2E979797"));
        wheelView3.setTextColorCenter(Color.parseColor("#000000"));
        wheelView3.setLineSpacingMultiplier(2.5f);
        wheelView3.setDividerType(WheelView.DividerType.WRAP);
        wheelView3.setCurrentItem(0);
        wheelView3.setItemsVisibleCount(5);
        wheelView3.setCyclic(true);
        wheelView3.setTextSize(15);
        //设置滚轮数据
        List<String> listYear = new ArrayList<>();//年 1980-2040
        for (int i = 0; i < 61; i++) {
            listYear.add(String.valueOf(1980 + i));
        }
        List<String> listMonth = new ArrayList<>();//月 12
        for (int i = 0; i < 12; i++) {
            listMonth.add(String.valueOf((i + 1) < 10 ? "0" + (i + 1) : i + 1));
        }
        WheelAdapter adapter1 = new ArrayWheelAdapter(listYear);
        wheelView1.setAdapter(adapter1);
        WheelAdapter adapter2 = new ArrayWheelAdapter(listMonth);
        wheelView2.setAdapter(adapter2);
        setDayDate(31);//日 默认显示1月 共31天

        //监听月份滚动选择
        wheelView2.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                index = index + 1;
                if (index == 1 || index == 3 || index == 5 || index == 7 || index == 8 || index == 10 || index == 12) {
                    //大月31天
                    setDayDate(31);
                } else if (index == 2) {
                    //2月判断是闰(29)还是平(28)
                    if (TimeUtils.isLeapYear(TimeUtils.getNowString(format), format)) {
                        setDayDate(29);
                    } else {
                        setDayDate(28);
                    }
                } else {
                    //小月30天
                    setDayDate(30);
                }
            }
        });
        //滚动到对应日期
        String date = TimeUtils.getNowString(new SimpleDateFormat("yyyy-MM-dd"));
        String[] split = date.split("-");
        int year = Integer.parseInt(split[0]);//年
        int moon = Integer.parseInt(split[1]);//月
        int day = Integer.parseInt(split[2]);//日
        wheelView1.setCurrentItem(year - 1980);
        wheelView2.setCurrentItem(moon - 1);
        wheelView3.setCurrentItem(day - 1);
    }

    //设置天
    private void setDayDate(int num) {
        List<String> listDay = new ArrayList<>();//日 默认显示1月31天
        for (int i = 0; i < num; i++) {
            listDay.add(String.valueOf((i + 1) < 10 ? "0" + (i + 1) : i + 1));
        }
        WheelAdapter adapter3 = new ArrayWheelAdapter(listDay);
        wheelView3.setAdapter(adapter3);
    }

    //选择工资弹框
    private void selWageDialog() {
        mySelWageDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_sel_wage, null);
        mySelWageDialog.setContentView(inflate);
        //获取当前Activity所在的窗体
        Window dialogWindow = mySelWageDialog.getWindow();
        //设置Dialog从窗体中心弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics dm = getResources().getDisplayMetrics();
        lp.width = (int) (dm.widthPixels * 1);
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        TextView dialogSet = inflate.findViewById(R.id.tvDialogSelWageSet);
        ImageView dialogCancel = inflate.findViewById(R.id.ivDialogSelWageCancel);
        ImageView dialogRight = inflate.findViewById(R.id.ivDialogSelWageRight);
        RecyclerView recyclerView = inflate.findViewById(R.id.rvTypeList);
        dialogSet.setOnClickListener(this);
        dialogCancel.setOnClickListener(this);
        dialogRight.setOnClickListener(this);

        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(overtimeWageAdapter);
        setOvertimeWage();
    }

    //选择请假类型弹框
    private void selLeaveDialog() {
        mySelLeaveDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_sel_leave, null);
        mySelLeaveDialog.setContentView(inflate);
        //获取当前Activity所在的窗体
        Window dialogWindow = mySelLeaveDialog.getWindow();
        //设置Dialog从窗体中心弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics dm = getResources().getDisplayMetrics();
        lp.width = (int) (dm.widthPixels * 1);
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        ImageView dialogCancel = inflate.findViewById(R.id.ivDialogSelLeaveCancel);
        ImageView dialogRight = inflate.findViewById(R.id.ivDialogSelLeaveRight);
        RecyclerView recyclerView = inflate.findViewById(R.id.rvTypeList);
        dialogCancel.setOnClickListener(this);
        dialogRight.setOnClickListener(this);

        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(leaveWageAdapter);
        setLeaveWage();
    }

    private void setOvertimeWage() {
        List<WageBean> list = new ArrayList<>();
        double wage1 = Str2NumUtil.parse(SPUtil.getString(mContext, Content.wageTyp1, "15.0"));
        double wage2 = Str2NumUtil.parse(SPUtil.getString(mContext, Content.wageTyp2, "20.0"));
        double wage3 = Str2NumUtil.parse(SPUtil.getString(mContext, Content.wageTyp3, "30.0"));
        double times1 = Str2NumUtil.parse(SPUtil.getString(mContext, Content.wageTimes1, "1.5"));
        double times2 = Str2NumUtil.parse(SPUtil.getString(mContext, Content.wageTimes2, "2"));
        double times3 = Str2NumUtil.parse(SPUtil.getString(mContext, Content.wageTimes3, "3"));
        list.add(new WageBean(wage1, getString(R.string.overtime_type1) + times1 + getString(R.string.unit_times) + getString(R.string.hour_income, wage1), true));
        list.add(new WageBean(wage2, getString(R.string.overtime_type2) + times2 + getString(R.string.unit_times) + getString(R.string.hour_income, wage2), false));
        list.add(new WageBean(wage3, getString(R.string.overtime_type3) + times3 + getString(R.string.unit_times) + getString(R.string.hour_income, wage3), false));
        overtimeWageAdapter.setList(list);
        if (overtimeBean == null) {
            overtimeWage = wage1;
            mDataBinding.tvOvertimeWage.setText(list.get(0).getName());
        }
    }

    private void setLeaveWage() {
        List<WageBean> list = new ArrayList<>();
        double wage = Str2NumUtil.parse("-" + SPUtil.getString(mContext, Content.hourWage, "15"));
        list.add(new WageBean(0, getString(R.string.leave_type1) + getString(R.string.hour_income, 0f), true));
        list.add(new WageBean(wage, getString(R.string.leave_type2) + getString(R.string.hour_income, wage), false));
        list.add(new WageBean(wage, getString(R.string.leave_type3) + getString(R.string.hour_income, wage), false));
        list.add(new WageBean(0, getString(R.string.leave_type4) + getString(R.string.hour_income, 0f), false));
        leaveWageAdapter.setList(list);
        if (overtimeBean == null) {
            leaveWage = 0;
            mDataBinding.tvLeaveWage.setText(list.get(0).getName());
        }
    }

    private void clearSelection() {
        mDataBinding.tvRecordOvertime.setTextColor(Color.parseColor("#000000"));
        mDataBinding.tvRecordOvertime.setTextSize(16);
        mDataBinding.ivRecordOvertimeSel.setVisibility(View.INVISIBLE);
        mDataBinding.llOvertime.setVisibility(View.GONE);
        mDataBinding.tvRecordLeave.setTextColor(Color.parseColor("#000000"));
        mDataBinding.tvRecordLeave.setTextSize(16);
        mDataBinding.ivRecordLeaveSel.setVisibility(View.INVISIBLE);
        mDataBinding.llLeave.setVisibility(View.GONE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == Content.SEL_WAGE) {
                setOvertimeWage();
            }
        }
    }

}